<template>
	<view style="height: 83vh; overflow-y: auto;">
		<view class="dd">
			<!-- 顶部导航栏 -->
			<scroll-view class="scroll-view_H" scroll-x="true" @scroll="scroll">
				<view>
					<view class="scroll-view-item_H" v-for="(tab, index) in tabBars" :key="tab.id" :id="tab.id"
						:class="navIndex === index ? 'activite' : ''" @tap="checkIndex(index)">
						{{ tab.name }}
					</view>
				</view>
			</scroll-view>
		</view>
		<view class="box_all">
			<swiper :current="navIndex" @change="tabChange" class="content1" style="height: 100%;">
				<!-- 全部 -->
				<swiper-item class="swiper_item">
					<view v-if="store.length === 0" class="no-data">暂无审核数据</view>
					<view v-else class="box6" v-for="item in store" :key="item.id">
						<view class="ll1">店铺名称: <text class="ll2">{{ item.shop_name }}</text></view>
						<view class="ll1">店铺地址: <text class="ll2">{{ item.address }}</text></view>
						<view class="ll1">订单编号: <text class="ll2">{{ item.id }}</text></view>
						<view class="ll1">应付金额: <text class="ll2">{{ item.price }}¥</text></view>
						<view class="ll1">实付金额: <text class="ll2">{{ item.price }}¥</text></view>
						<view class="box6-1">
							<text v-show="item.paystate == 1">状态:<text style="color: #60c567;">已通过</text></text>
							<text v-show="item.paystate == 3">状态:<text style="color: #f43d13;">未通过</text></text>
							<text v-show="item.paystate == 2">状态:<text style="color: #f3b516;">待审核</text></text>
							<view class="box6-2">
								<button class="mini-btn" type="primary" size="mini"
									@click="shtz(item.id)">审核</button>
							</view>
						</view>
					</view>
				</swiper-item>
				<!-- 待审核 -->
				<swiper-item class="swiper_item">
					<view v-if="daishenhe.length === 0" class="no-data">暂无审核数据</view>
					<view v-else class="box6" v-for="item in daishenhe" :key="item.id">
						<view class="ll1">店铺名称: <text class="ll2">{{ item.shop_name }}</text></view>
						<view class="ll1">店铺地址: <text class="ll2">{{ item.address }}</text></view>
						<view class="ll1">订单编号: <text class="ll2">{{ item.id }}</text></view>
						<view class="ll1">应付金额: <text class="ll2">{{ item.price }}¥</text></view>
						<view class="ll1">实付金额: <text class="ll2">{{ item.price }}¥</text></view>
						<view class="box6-1">
							<text v-show="item.paystate == 1">状态:<text style="color: #60c567;">已通过</text></text>
							<text v-show="item.paystate == 3">状态:<text style="color: #f43d13;">未通过</text></text>
							<text v-show="item.paystate == 2">状态:<text style="color: #f3b516;">待审核</text></text>
							<view class="box6-2">
								<button class="mini-btn" type="primary" size="mini"
									@click="shtz(item.id)">审核</button>
							</view>
						</view>
					</view>
				</swiper-item>
				<!-- 已通过 -->
				<swiper-item class="swiper_item">
					<view v-if="yitongguo.length === 0" class="no-data">暂无审核数据</view>
					<view v-else class="box6" v-for="item in yitongguo" :key="item.id">
						<view class="ll1">店铺名称: <text class="ll2">{{ item.shop_name }}</text></view>
						<view class="ll1">店铺地址: <text class="ll2">{{ item.address }}</text></view>
						<view class="ll1">订单编号: <text class="ll2">{{ item.id }}</text></view>
						<view class="ll1">应付金额: <text class="ll2">{{ item.price }}¥</text></view>
						<view class="ll1">实付金额: <text class="ll2">{{ item.price }}¥</text></view>
						<view class="box6-1">
					<text v-show="item.paystate == 1">状态:<text style="color: #60c567;">已通过</text></text>
					<text v-show="item.paystate == 3">状态:<text style="color: #f43d13;">未通过</text></text>
					<text v-show="item.paystate == 2">状态:<text style="color: #f3b516;">待审核</text></text>
							<view class="box6-2">
								<button class="mini-btn" type="primary" size="mini"
									@click="shtz(item.id)">审核</button>
							</view>
						</view>
					</view>
				</swiper-item>
				<!-- 未通过 -->
				<swiper-item class="swiper_item">
					<view v-if="weitongguo.length === 0" class="no-data">暂无审核数据</view>
					<view v-else class="box6" v-for="item in weitongguo" :key="item.id">
						<view class="ll1">店铺名称: <text class="ll2">{{ item.shop_name }}</text></view>
						<view class="ll1">店铺地址: <text class="ll2">{{ item.address }}</text></view>
						<view class="ll1">订单编号: <text class="ll2">{{ item.id }}</text></view>
						<view class="ll1">应付金额: <text class="ll2">{{ item.price }}¥</text></view>
						<view class="ll1">实付金额: <text class="ll2">{{ item.price }}¥</text></view>
						<view class="box6-1">
							<text v-show="item.paystate == 1">状态:<text style="color: #60c567;">已通过</text></text>
							<text v-show="item.paystate == 3">状态:<text style="color: #f43d13;">未通过</text></text>
							<text v-show="item.paystate == 2">状态:<text style="color: #f3b516;">待审核</text></text>
							<view class="box6-2">
								<button class="mini-btn" type="primary" size="mini"
									@click="shtz(item.id)">审核</button>
							</view>
						</view>
					</view>
				</swiper-item>
			</swiper>
		</view>
	</view>
	<!-- <tabBar></tabBar> -->
</template>
<script setup>
	import {
		ref,
		onMounted
	} from 'vue';
	import {
		http
	} from '/until/request.js';

	// 声明响应式状态
	const scrollTop = ref(0);
	const navIndex = ref(0);
	const tabBars = ref([{
			id: 'tab1',
			name: '全部'
		},
		{
			id: 'tab2',
			name: '待审核'
		},
		{
			id: 'tab3',
			name: '已通过'
		},
		{
			id: 'tab4',
			name: '未通过'
		}
	]);

	// 审核全部
	const store = ref([]);

	// 待审核
	const daishenhe = ref([]);

	// 已通过
	const yitongguo = ref([]);

	// 未通过
	const weitongguo = ref([]);

	// 获取审核列表
	const fetchAuditList = async () => {
		const data = await http({
			url: '/audit/getAuditList',
			method: 'get'
		});
		store.value = data.data; // 假设后端返回的数据在data字段中
		console.log("11111111");
		console.log(store.value);

		// 循环store数组并以store.reviewStatus作为判断条件
		store.value.forEach(item => {
			// 1已通过 2待审核 3未通过
			if (item.paystate == 1) {
				yitongguo.value.push(item);
			} else if (item.paystate == 2) {
				daishenhe.value.push(item);
			} else if (item.paystate == 3) {
				weitongguo.value.push(item);
			}
		});

		console.log("全部");
		console.log(store.value);
		console.log("待审核");
		console.log(daishenhe.value);
		console.log("已通过");
		console.log(yitongguo.value);
		console.log("未通过");
		console.log(weitongguo.value);
	};

	// 格式化时间
	const formattedTime = (createTime) => {
		if (!createTime) return '';
		const date = new Date(createTime);
		const year = date.getFullYear();
		const month = String(date.getMonth() + 1).padStart(2, '0');
		const day = String(date.getDate()).padStart(2, '0');
		return `${year}-${month}-${day}`;
	};

	// 页面加载时获取审核列表
	onMounted(() => {
		fetchAuditList();
	});

	// 定义方法
	const checkIndex = (index) => {
		console.log(index);
		navIndex.value = index;
		fetchOrders();
	};

	const fetchOrders = () => {
		// 模拟获取订单数据的逻辑
		console.log('Fetching orders with status:', navIndex.value);
	};

	const scroll = (event) => {
		// 处理滚动事件的逻辑
		console.log('Scroll event:', event);
	};

	const tabChange = (event) => {
		navIndex.value = event.detail.current;
	};

	// 点击审核按钮跳转
	const shtz = (id) => {
		
		uni.navigateTo({
			url: `/pages/supplier/djshenhe/djhuankuan?id=${id}`
		});
	};
</script>
<style lang="scss" scoped>
	.mini-btn {
		margin-left: 120rpx;
		width: 200rpx;
		background: linear-gradient(to right, #0496d9, #0496d9);
		color: white;
		font-size: 35rpx;
		box-shadow: 2rpx 2rpx 6rpx rgba(0, 0, 0, 0.2);
		box-shadow: inset 0 -2rpx 0 rgba(0, 0, 0, 0.1), 2rpx 2rpx 6rpx rgba(0, 0, 0, 0.2);
		text-shadow: 1rpx 1rpx 2rpx rgba(0, 0, 0, 0.2);
		transition: background 0.3s ease, transform 0.3s ease;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;

		&:hover {
			transform: scale(1.05);
			background: linear-gradient(to right, #0496d9, #0496d9);
		}

		&:active {
			transform: scale(0.95);
			background: #0496d9;
		}
	}

	.swiper_item {
		overflow-y: auto;
	}

	.box_all {
		height: 100%;
	}

	.activite {
		color: #007aff;
		// border-bottom: 2px solid #007aff;
	}

	.scroll-view_H {
		white-space: nowrap;
		width: 100%;
		background-color: #fff;
	}

	.scroll-view-item_H {
		display: inline-block;
		padding: 20px 20px;
		text-align: center;
		font-size: 16px;
		// border: #FF0000 1px solid;
		margin-left: 25rpx;
	}

	.no-data {
		margin-top: 520rpx;
		color: lightslategrey;
		display: flex;
		justify-content: center;
		align-items: center;
		font-size: 35rpx;
	}

	view {
		margin: 0;
		padding: 0;
	}

	page {
		background-color: #F5F5F5;
	}

	.all {
		background-color: #fff;
		padding-bottom: 60px;
	}

	.notAud {
		background-color: white;
		text-align: center;
		margin-top: 10px;
		height: 150px;
		line-height: 250px;
		font-size: 21px;
	}

	.box {
		background-color: #fff;
		width: 750rpx;
		height: 100rpx;
		display: flex;
		position: sticky;
		top: 0;
		z-index: 1;
		text-align: center;
	}

	.box6 {
		margin-top: 50rpx;
		margin-bottom: 25rpx;
		box-shadow: 8px 5px 5px rgba(117, 160, 208, 0.3);
		padding-left: 10rpx;
		padding-top: 20rpx;
		display: flex;
		flex-direction: column;
		align-items: flex-start;

		.ll1 {
			font-size: 35rpx;
			font-weight: 600;

			.ll2 {
				font-weight: 500;
			}
		}

		.box6-1 {
			font-size: 35rpx;
			margin-top: 10rpx;
			// color: red;
			font-weight: bold;
		}

		.box6-2 {
			display: flex;
			padding-left: 400rpx;
			margin-top: -50rpx;
		}
	}

	.box6>view {
		margin-bottom: 8px;
		font-size: 14px;
		color: #333;
	}

	.box6>view>text {
		/* 单独为text元素设置样式（如果需要的话） */
	}

	.type-1 {
		background-color: #fff;
		width: 100%;
		height: 40px;

		.type {
			width: 150rpx;
			height: 30px;
			line-height: 30px;
			float: right;
			margin-top: 5px;
			margin-right: 30rpx;
			background-color: #EEFBF4;
			text-align: center;

			text {
				color: #1BC477;
			}
		}
	}

	.type-2 {
		background-color: #fff;
		width: 100%;
		height: 40px;

		.type {
			width: 150rpx;
			height: 30px;
			line-height: 30px;
			float: right;
			margin-top: 5px;
			margin-right: 30rpx;
			background-color: #FBEEEE;
			text-align: center;

			text {
				color: #FF0000;
			}
		}
	}

	.type-3 {
		background-color: #fff;
		width: 100%;
		height: 40px;

		.type {
			width: 150rpx;
			height: 30px;
			line-height: 30px;
			float: right;
			margin-top: 5px;
			margin-right: 30rpx;
			background-color: #FFF7E6;
			text-align: center;

			text {
				color: #FFB114;
			}
		}
	}
</style>